package com.example.tse.rbhttpservice.service.member;


import android.content.Context;

import com.example.tse.rbhttpservice.service.HttpService;
import com.example.tse.rbhttpservice.service.RemoteServiceListenerT;
import com.example.tse.rbhttpservice.service.ResponseServiceListenerT;
import com.example.tse.rbhttpservice.service.RudderResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoGetRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoGetResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoGetStatRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoGetStatResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpAvatarRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpAvatarResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpByRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpByResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpPwdRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberInfoUpPwdResponse;
import com.google.gson.Gson;

import org.kymjs.kjframe.http.HttpParams;





/**
 *
 * @author wliu
 *    edi  tse
 */
public class MemberInfoServiceImpl implements MemberInfoService {
	private Context context;
	private static Gson gson = new Gson();


	public MemberInfoServiceImpl(Context context) {
		this.context = context;
	}
	/**
	 * 进入个人中心页面需要显示我的关注、我的粉丝数量、
	 * @param request
	 * @param listener
	 * @return MemberInfoGetStatResponse
	 */

	    public void getStat(MemberInfoGetStatRequest request, final RemoteServiceListenerT< MemberInfoGetStatResponse> listener) {

        final HttpParams params = new HttpParams();



        final String url = "member/info/getStat";


            new HttpService().get(context, url, params, MemberInfoGetStatResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberInfoGetStatResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberInfoGetStatResponse() : (MemberInfoGetStatResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberInfoGetStatResponse() : (MemberInfoGetStatResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 获取用户的个人信息
	 * @param request
	 * @param listener
	 * @return MemberInfoGetResponse
	 */

	    public void get(MemberInfoGetRequest request, final RemoteServiceListenerT< MemberInfoGetResponse> listener) {

        final HttpParams params = new HttpParams();



        final String url = "member/info/get";


            new HttpService().get(context, url, params, MemberInfoGetResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberInfoGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberInfoGetResponse() : (MemberInfoGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberInfoGetResponse() : (MemberInfoGetResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 更新用户头像，保留直接选择文件上传功能
	 * @param request
	 * @param listener
	 * @return MemberInfoUpAvatarResponse
	 */

	    public void upAvatar(MemberInfoUpAvatarRequest request, final RemoteServiceListenerT< MemberInfoUpAvatarResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("file",request.getFile());

        final String url = "member/info/upAvatar";


            new HttpService().post(context, url, params, MemberInfoUpAvatarResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberInfoUpAvatarResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberInfoUpAvatarResponse() : (MemberInfoUpAvatarResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberInfoUpAvatarResponse() : (MemberInfoUpAvatarResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 更新用户信息，根据类型修改不同字段
	 * @param request
	 * @param listener
	 * @return MemberInfoUpByResponse
	 */

	    public void upBy(MemberInfoUpByRequest request, final RemoteServiceListenerT< MemberInfoUpByResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("value",request.getValue());
            params.put("type",request.getType());

        final String url = "member/info/upBy";


            new HttpService().post(context, url, params, MemberInfoUpByResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberInfoUpByResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberInfoUpByResponse() : (MemberInfoUpByResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberInfoUpByResponse() : (MemberInfoUpByResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




	/**
	 * 修改密码
	 * @param request
	 * @param listener
	 * @return MemberInfoUpPwdResponse
	 */

	    public void upPwd(MemberInfoUpPwdRequest request, final RemoteServiceListenerT< MemberInfoUpPwdResponse> listener) {

        final HttpParams params = new HttpParams();


            params.put("oldPassword",request.getOldPassword());
            params.put("password",request.getPassword());

        final String url = "member/info/upPwd";


            new HttpService().post(context, url, params, MemberInfoUpPwdResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberInfoUpPwdResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberInfoUpPwdResponse() : (MemberInfoUpPwdResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberInfoUpPwdResponse() : (MemberInfoUpPwdResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }

            @Override
            public void onMessage(String message) {
                super.onMessage(message);
                listener.onMessage(message);
            }
        });
    }




}